//
//  SecondViewController.m
//  王宇先_07_导航栏控制器
//
//  Created by wyx on 16/3/17.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "SecondViewController.h"
#import "ViewController.h"
#import "Segment.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target: self action:@selector(handleOfBack:)]autorelease];
    [self configNaviBar];
    [self creatSegment];
}
//隐藏 Bar
-(void)configNaviBar {
    self.navigationController.navigationBarHidden = NO;
}
//返回首页
- (void)handleOfBack:(UIBarButtonItem *)back {
    ViewController *first = [[ViewController alloc] init];
    [self.navigationController pushViewController:first animated:YES];
    
    [first release];
}
//添加Segment
- (void)creatSegment{
    //数组中放入字符串对象 或者image对象
    Segment *seg = [[Segment alloc]initWithItems:@[@"第2.1页",@"第2.2页"]];
    seg.frame = CGRectMake(50, 0, 100, 30);
    /** 核心 API 把 Segment 添加到 navigationItem 上 */
    [self.navigationItem setTitleView:seg];
    [seg release];
    [seg addTarget:self action:@selector(handleseg:) forControlEvents:UIControlEventValueChanged];
}
- (void)handleseg: (Segment *)seg{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
